package com.heima.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @作者 itcast
 * @创建日期 2021/11/18 14:27
 **/
@RestController
@RequestMapping("/api/v1/user")
public class WmUserController {
    @Autowired
    WmUserService wmUserService;
    @GetMapping("findByName/{name}")
    public ResponseResult findByName(@PathVariable String name){
        WmUser one = wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
        return ResponseResult.okResult(one);
    }
    @PostMapping("save")
    public ResponseResult save(@RequestBody WmUser user){
        user.setCreatedTime(new Date());
        // user.id == null
        wmUserService.save(user);  // 先创建自媒体账号   创建作者信息 需要自媒体账户id
        // user.id == 有值
        return ResponseResult.okResult(user);
    }

}
